package com.xiangyang.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xiangyang.entity.Department;
import com.xiangyang.entity.OperLog;
import com.xiangyang.entity.dto.Result;
import com.xiangyang.entity.vo.OperLogLikeAndPage;
import com.xiangyang.mapper.IDepartmentMapper;
import com.xiangyang.mapper.OperLogMapper;
import com.xiangyang.service.ISelectInfoService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SelectInfoServiceImpl implements ISelectInfoService {
    @Autowired
    private IDepartmentMapper departmentMapper;
    @Autowired
    private OperLogMapper operLogMapper;

    public Result getAllDepartmentName() {
        LambdaQueryWrapper<Department> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(Department::getDepartmentName);
        List<Department> list = departmentMapper.selectList(queryWrapper);
        List<String> listName = list.stream().map(Department::getDepartmentName).toList();
        return Result.ok(listName);
    }

    @Override
    public Result selectoperlogInfo(OperLogLikeAndPage operLog) {
         Page<OperLog> page = new Page<>(operLog.getPage(), operLog.getSize());
         LambdaQueryWrapper<OperLog> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.like(OperLog::getOperName, operLog.getOperName());
         queryWrapper.like(OperLog::getBusinessType, operLog.getBusinessType());
         return Result.ok(operLogMapper.selectPage(page,queryWrapper));
    }

    @Override
    public Result deleteOperLog() {
        return operLogMapper.delete(new QueryWrapper<>())>0?Result.ok("清除成功"):Result.error("删除失败");
    }


}
